<!DOCTYPE html>

<html lang="en">
  <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>访问控制列表 ACL（Access Control Lists ACL） &mdash; Phalcon 2.0.0 文档</title>
    <meta name="keywords" content="php, phalcon, phalcon php, php framework, faster php framework"><link rel="stylesheet" type="text/css" href="../_static/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="http://static.phalconphp.com/css/phalcon.min.css" />
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400' rel='stylesheet' type='text/css'>
    <link href="http://fonts.googleapis.com/css?family=Merriweather:400,700" rel="stylesheet" type="text/css" />
    <!--
    EUROPE <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=latin-ext' rel='stylesheet' type='text/css'>
    GREEK <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=greek-ext' rel='stylesheet' type='text/css'>
    RUSSIA <link href='https://fonts.googleapis.com/css?family=Open+Sans:700,400&subset=cyrillic-ext,latin' rel='stylesheet' type='text/css'>
    -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.0.0',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>

    <script src="../_static/jquery.min.js"></script>
    <script type="text/javascript" src="../_static/docs.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="Phalcon 2.0.0 文档" href="../index.html" />
    <link rel="next" title="多语言支持（Multi-lingual Support）" href="translate.html" />
    <link rel="prev" title="加密与解密（Encryption/Decryption）" href="crypt.html" /> 
  </head>
  <body>

<header class="page-header">
    <nav class="navbar" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-container">
                    <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="navbar-brand phalcon-logo" href="/"><span itemprop="name" class="sr-only">Phalcon PHP</span></a>
            </div>

            <div class="collapse navbar-collapse navbar-right" id="main-menu-container">
                <ul class="nav navbar-nav main-menu">
                  <li class="first"><a href="http://phalconphp.com/en/download" class="header-nav-link">Download</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="http://blog.phalconphp.com/" class="header-nav-link" target="_blank">Blog</a></li>
                  <li><a href="http://phalconphp.com/en/about">About</a></li>
                </ul>
            </div>
        </div>
    </nav>
  </header>

<div class="heading">
    <div class="container">
        <div class="row">
            <h2>Documentation</h2>
        </div>
    </div>
</div>
    <!--<div class="header-line">
      <div class="size-wrap">
        <div class="header-line-title title-white">Documentation</div>
      </div>
    </div>-->
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="translate.html" title="多语言支持（Multi-lingual Support）"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="crypt.html" title="加密与解密（Encryption/Decryption）"
             accesskey="P">上一页</a> |</li>
        <li><a href="http://phalconphp.com">Home</a> &raquo;</li>
        <li><a href="../index.html">Phalcon 2.0.0 文档</a> &raquo;</li> 
      </ul>
    </div>  

      <table width="100%" align="center" cellpadding="0" cellspacing="0">
        <tr>
      <td class="primary-box" width="25%" valign="top">
            <div>
            <div id="searchbox" style="">
                <!--<form class="search" action="http://readthedocs.org/search/project/" method="get">
                  <input type="search" name="q" size="25" placeholder="Search">
                  <input type="submit" value="Go">
                  <input type="hidden" name="selected_facets" value="project:">
                </form>-->
                <div style="width:200px;padding:10px">
                  <gcse:searchbox-only></gcse:searchbox-only>
                </div>
            </div>
            </div>
            <div style="padding:5px;padding-left:10px">
              <div id="carbonads-container">
                <div class="carbonad"><div id="azcarbon"></div>
                <script type="text/javascript">var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = "http://engine.carbonads.com/z/56496/azcarbon_2_1_0_VERT"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);</script>
                </div></div>
            </div>
            <h3><a href="../index.html">內容目录</a></h3>
            <ul>
<li><a class="reference internal" href="#">访问控制列表 ACL（Access Control Lists ACL）</a><ul>
<li><a class="reference internal" href="#acl-creating-an-acl">创建 ACL（Creating an ACL）</a></li>
<li><a class="reference internal" href="#adding-roles-to-the-acl">添加角色（Adding Roles to the ACL）</a></li>
<li><a class="reference internal" href="#adding-resources">添加资源（Adding Resources）</a></li>
<li><a class="reference internal" href="#defining-access-controls">定义访问控制（Defining Access Controls）</a></li>
<li><a class="reference internal" href="#acl-querying-an-acl">查询 ACL（Querying an ACL）</a></li>
<li><a class="reference internal" href="#roles-inheritance">角色继承（Roles Inheritance）</a></li>
<li><a class="reference internal" href="#acl-serializing-acl-lists">序列化 ACL 列表（Serializing ACL lists）</a></li>
<li><a class="reference internal" href="#acl-acl-events">ACL 事件（ACL Events）</a></li>
<li><a class="reference internal" href="#implementing-your-own-adapters">自定义适配器（Implementing your own adapters）</a></li>
</ul>
</li>
</ul>

            <h4>上一个主题</h4>
            <p class="topless"><a href="crypt.html" title="上一章">&lt; 加密与解密（Encryption/Decryption）</a></p>
            <h4>下一个主题</h4>
            <p class="topless"><a href="translate.html" title="下一章">多语言支持（Multi-lingual Support） &gt;</a></p>
            <h3>本页</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/reference/acl.txt" rel="nofollow">显示源代码</a></li>
            </ul>
        </td>
          <td class="second-box" valign="top">
            <div class="document">
                <div class="documentwrapper">
                  <div class="bodywrapper">
                    <div class="body" >
                      
  <div class="section" id="acl-access-control-lists-acl">
<h1>访问控制列表 ACL（Access Control Lists ACL）<a class="headerlink" href="#acl-access-control-lists-acl" title="永久链接至标题">¶</a></h1>
<p>Phalcon在权限方面通过 <a class="reference internal" href="../api/Phalcon_Acl.html"><em>Phalcon\Acl</em></a> 提供了一个轻量级的 ACL(访问控制列表). <a class="reference external" href="http://en.wikipedia.org/wiki/Access_control_list">Access Control Lists</a> (ACL)
允许系统对用户的访问权限进行控制，比如允许访问某些资源而不允许访问其它资源等。 这里我们建议开发者了解一些关于ACL的技术。</p>
<p>ACL有两部分组成即角色和资源。 资源即是ACL定义的权限所依附的对象。 角色即是ACL所字义的请求者的身份，ACL决定了角色对资源的访问权限，允许访问或拒绝访问。</p>
<div class="section" id="acl-creating-an-acl">
<h2>创建 ACL（Creating an ACL）<a class="headerlink" href="#acl-creating-an-acl" title="永久链接至标题">¶</a></h2>
<p>这个组件起先是设计工作在内存中的， 这样做提供了更高的访问速度。 <a class="reference internal" href="../api/Phalcon_Acl.html"><em>Phalcon\Acl</em></a> 构造器的第一个参数用于设置取得ACL的方式。 下面是使用内存适配器的例子：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Adapter\Memory</span> <span class="k">as</span> <span class="nx">AcList</span><span class="p">;</span>

<span class="nv">$acl</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AclList</span><span class="p">();</span>
</pre></div>
</div>
<p>默认情况下 <a class="reference internal" href="../api/Phalcon_Acl.html"><em>Phalcon\Acl</em></a> 允许我们访问未定义的资源中的action，为了提高安全性， 我们设置默认访问级别为‘拒绝’。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// 设置默认访问级别为拒绝</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">setDefaultAction</span><span class="p">(</span><span class="nx">Phalcon\Acl</span><span class="o">::</span><span class="na">DENY</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="adding-roles-to-the-acl">
<h2>添加角色（Adding Roles to the ACL）<a class="headerlink" href="#adding-roles-to-the-acl" title="永久链接至标题">¶</a></h2>
<p>角色即是权限的集合体，其中定义了我们对资源的访问权限。 例如， 我们会把一个组织内的不同的人定义为不同的角色。 The <a class="reference internal" href="../api/Phalcon_Acl_Role.html"><em>Phalcon\Acl\Role</em></a>
类使用一种更有组织的方式来定义角色。 这里我们创建一些角色：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Role</span><span class="p">;</span>

<span class="c1">// 创建角色</span>
<span class="nv">$roleAdmins</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Role</span><span class="p">(</span><span class="s2">&quot;Administrators&quot;</span><span class="p">,</span> <span class="s2">&quot;Super-User role&quot;</span><span class="p">);</span>
<span class="nv">$roleGuests</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Role</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">);</span>

<span class="c1">//添加 &quot;Guests&quot; 角色到acl</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addRole</span><span class="p">(</span><span class="nv">$roleGuests</span><span class="p">);</span>

<span class="c1">//添加&quot;Designers&quot;到acl, 仅使用此字符串。</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addRole</span><span class="p">(</span><span class="s2">&quot;Designers&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>上面我们看到，我们可以直接使用字符串来定义角色。</p>
</div>
<div class="section" id="adding-resources">
<h2>添加资源（Adding Resources）<a class="headerlink" href="#adding-resources" title="永久链接至标题">¶</a></h2>
<p>资源即是访问控制要控制的对象之一。 正常情况下在mvc中资源一般是控制器。 Phalcon中我们使用 <a class="reference internal" href="../api/Phalcon_Acl_Resource.html"><em>Phalcon\Acl\Resource</em></a> 来定义资源。
非常重要的一点即是我们把相关的action或操作添加到资源中这样ACL才知道控制什么资源。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Resource</span><span class="p">;</span>

<span class="c1">// 定义 &quot;Customers&quot; 资源</span>
<span class="nv">$customersResource</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Resource</span><span class="p">(</span><span class="s2">&quot;Customers&quot;</span><span class="p">);</span>

<span class="c1">// 为 &quot;customers&quot;资源添加一组操作</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addResource</span><span class="p">(</span><span class="nv">$customersResource</span><span class="p">,</span> <span class="s2">&quot;search&quot;</span><span class="p">);</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addResource</span><span class="p">(</span><span class="nv">$customersResource</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s2">&quot;create&quot;</span><span class="p">,</span> <span class="s2">&quot;update&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="defining-access-controls">
<h2>定义访问控制（Defining Access Controls）<a class="headerlink" href="#defining-access-controls" title="永久链接至标题">¶</a></h2>
<p>至此我们定义了角色及资源， 现在是定义ACL的时候了，即是定义角色对资源的访问。 这个部分是极其重要的，特别是在我们设定了默认的访问级别后。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// 设置角色对资源的访问级别</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">allow</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;search&quot;</span><span class="p">);</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">allow</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;create&quot;</span><span class="p">);</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">deny</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;update&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>allow()方法指定了允许角色对资源的访问， deny()方法则反之。</p>
</div>
<div class="section" id="acl-querying-an-acl">
<h2>查询 ACL（Querying an ACL）<a class="headerlink" href="#acl-querying-an-acl" title="永久链接至标题">¶</a></h2>
<p>一旦访问控制表定义之后， 我们就可以通过它来检查角色是否有访问权限了。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="c1">// 查询角色是否有访问权限</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">isAllowed</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;edit&quot;</span><span class="p">);</span>   <span class="c1">//Returns 0</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">isAllowed</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;search&quot;</span><span class="p">);</span> <span class="c1">//Returns 1</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">isAllowed</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;create&quot;</span><span class="p">);</span> <span class="c1">//Returns 1</span>
</pre></div>
</div>
</div>
<div class="section" id="roles-inheritance">
<h2>角色继承（Roles Inheritance）<a class="headerlink" href="#roles-inheritance" title="永久链接至标题">¶</a></h2>
<p>我们可以使用 <a class="reference internal" href="../api/Phalcon_Acl_Role.html"><em>Phalcon\Acl\Role</em></a> 提供的继承机制来构造更复杂的角色。 Phalcon中的角色可以继承来自其它角色的
权限, 这样就可以实现更巧妙的资源访问控制。 如果要继承权限用户， 我们需要在添加角色函数的第二个参数中写上要继承的那个角色实例。</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Role</span><span class="p">;</span>

<span class="c1">// 创建角色</span>
<span class="nv">$roleAdmins</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Role</span><span class="p">(</span><span class="s2">&quot;Administrators&quot;</span><span class="p">,</span> <span class="s2">&quot;Super-User role&quot;</span><span class="p">);</span>
<span class="nv">$roleGuests</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Role</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">);</span>

<span class="c1">// 添加 &quot;Guests&quot; 到 acl.</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addRole</span><span class="p">(</span><span class="nv">$roleGuests</span><span class="p">);</span>

<span class="c1">// 使Administrators继承Guests的访问权限</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">addRole</span><span class="p">(</span><span class="nv">$roleAdmins</span><span class="p">,</span> <span class="nv">$roleGuests</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="acl-serializing-acl-lists">
<h2>序列化 ACL 列表（Serializing ACL lists）<a class="headerlink" href="#acl-serializing-acl-lists" title="永久链接至标题">¶</a></h2>
<p>为了提高性能， <a class="reference internal" href="../api/Phalcon_Acl.html"><em>Phalcon\Acl</em></a> 的实例可以被实例化到APC, session， 文本或数据库中， 这样开发者就不需要重复的
定义acl了。 下面展示了如何去做：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Adapter\Memory</span> <span class="k">as</span> <span class="nx">AclList</span><span class="p">;</span>

<span class="c1">// 检查acl数据是否存在</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">is_file</span><span class="p">(</span><span class="s2">&quot;app/security/acl.data&quot;</span><span class="p">))</span> <span class="p">{</span>

    <span class="nv">$acl</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AclList</span><span class="p">();</span>

    <span class="c1">//... Define roles, resources, access, etc</span>

    <span class="c1">// 保存实例化的数据到文本文件中</span>
    <span class="nb">file_put_contents</span><span class="p">(</span><span class="s2">&quot;app/security/acl.data&quot;</span><span class="p">,</span> <span class="nb">serialize</span><span class="p">(</span><span class="nv">$acl</span><span class="p">));</span>

<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>

     <span class="c1">// 返序列化</span>
     <span class="nv">$acl</span> <span class="o">=</span> <span class="nb">unserialize</span><span class="p">(</span><span class="nb">file_get_contents</span><span class="p">(</span><span class="s2">&quot;app/security/acl.data&quot;</span><span class="p">));</span>
<span class="p">}</span>

<span class="c1">// 使用acl</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">isAllowed</span><span class="p">(</span><span class="s2">&quot;Guests&quot;</span><span class="p">,</span> <span class="s2">&quot;Customers&quot;</span><span class="p">,</span> <span class="s2">&quot;edit&quot;</span><span class="p">))</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="s2">&quot;Access granted!&quot;</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
    <span class="k">echo</span> <span class="s2">&quot;Access denied :(&quot;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="acl-acl-events">
<h2>ACL 事件（ACL Events）<a class="headerlink" href="#acl-acl-events" title="永久链接至标题">¶</a></h2>
<p>如果需要的话 <a class="reference internal" href="../api/Phalcon_Acl.html"><em>Phalcon\Acl</em></a> 可以发送事件到 <a class="reference internal" href="events.html"><em>EventsManager</em></a> 。 这里我们为acl绑定事件。
其中一些事件的处理结果如果返回了false则表示正在处理的操作会被中止。
支持如下的事件：</p>
<table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="58%" />
<col width="20%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">事件名</th>
<th class="head">触发条件</th>
<th class="head">能否中止操作</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>beforeCheckAccess</td>
<td>在权限检查之前触发</td>
<td>Yes</td>
</tr>
<tr class="row-odd"><td>afterCheckAccess</td>
<td>在权限检查之后触发</td>
<td>No</td>
</tr>
</tbody>
</table>
<p>下面的例子中展示了如何绑定事件到此组件：</p>
<div class="highlight-php"><div class="highlight"><pre><span class="cp">&lt;?php</span>

<span class="k">use</span> <span class="nx">Phalcon\Acl\Adapter\Memory</span> <span class="k">as</span> <span class="nx">AclList</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Phalcon\Events\Manager</span> <span class="k">as</span> <span class="nx">EventsManager</span><span class="p">;</span>

<span class="c1">//创建事件管理器</span>
<span class="nv">$eventsManager</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">EventsManager</span><span class="p">();</span>

<span class="c1">// 绑定事件类型为acl</span>
<span class="nv">$eventsManager</span><span class="o">-&gt;</span><span class="na">attach</span><span class="p">(</span><span class="s2">&quot;acl&quot;</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="nv">$event</span><span class="p">,</span> <span class="nv">$acl</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="nv">$event</span><span class="o">-&gt;</span><span class="na">getType</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;beforeCheckAccess&quot;</span><span class="p">)</span> <span class="p">{</span>
         <span class="k">echo</span>   <span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">getActiveRole</span><span class="p">(),</span>
                <span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">getActiveResource</span><span class="p">(),</span>
                <span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">getActiveAccess</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">});</span>

<span class="nv">$acl</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AclList</span><span class="p">();</span>

<span class="c1">//Setup the $acl</span>
<span class="c1">//...</span>

<span class="c1">// 绑定eventsManager到acl组件</span>
<span class="nv">$acl</span><span class="o">-&gt;</span><span class="na">setEventsManager</span><span class="p">(</span><span class="nv">$eventManagers</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="implementing-your-own-adapters">
<h2>自定义适配器（Implementing your own adapters）<a class="headerlink" href="#implementing-your-own-adapters" title="永久链接至标题">¶</a></h2>
<p>开发者要创建自己的扩展或已存在适配器则需要实现此 <a class="reference internal" href="../api/Phalcon_Acl_AdapterInterface.html"><em>Phalcon\Acl\AdapterInterface</em></a> 接口。</p>
</div>
</div>


                    </div>
                  </div>
                </div>
            </div>
          </td>
        </tr>
      </table>
    <div class="related">
      <ul>
        <li class="right" >
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="translate.html" title="多语言支持（Multi-lingual Support）"
             >下一页</a> |</li>
        <li class="right" >
          <a href="crypt.html" title="加密与解密（Encryption/Decryption）"
             >上一页</a> |</li> 
      </ul>
    </div>

      <div class="prefooter">
  <div class="container">
      <div class="row">
          <div class="col-sm-3 text-right">
              <span>Follow along:</span>
          </div>
          <div class="col-sm-6 text-center">
              <a href="https://twitter.com/phalconphp" alt="Twitter" class="btn-social btn-social-twitter"><i class="icon-twitter"></i></a>
              <a href="https://www.facebook.com/pages/Phalcon-Framework/134230726685897" alt="Facebook" class="btn-social btn-social-facebook"><i class="icon-facebook"></i></a>
              <a href="https://plus.google.com/102376109340560896457" alt="Google+" class="btn-social btn-social-googleplus"><i class="icon-googleplus"></i></a>
              <a href="https://github.com/phalcon/cphalcon" alt="Github" class="btn-social btn-social-github"><i class="icon-github"></i></a>
          </div>
          <div class="col-sm-3">
          </div>
      </div>
  </div>

</div>
<footer class="footer">
  <div class="container">
      <div class="row">
          <div class="col-xs-4 col-sm-3">
              <h4>Download</h4>
              <ul>
                  <li><a href="http://phalconphp.com/download">Installing Phalcon</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/index.html" class="header-nav-link" target="_blank">Documentation</a></li>
                  <li><a href="http://api.phalconphp.com">API</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html">Tutorial</a></li>
                  <li><a href="http://docs.phalconphp.com/en/latest/reference/tutorial.html#sample-applications">Sample Applications</a></li>
              </ul>
          </div>
          <div class="col-xs-4 col-sm-3">
              <h4>Community</h4>
              <ul>
                  <li><a href="http://forum.phalconphp.com/" class="header-nav-link" target="_blank">Forum</a></li>
                  <li><a href="https://github.com/phalcon/cphalcon">GitHub</a></li>
                  <li><a href="https://github.com/phalcon/cphalcon/issues">Issue Tracker</a></li>
                  <li><a href="http://stackoverflow.com/questions/tagged/phalcon">Stack Overflow</a></li>
                  <li><a href="http://phalconphp.com/en/testimonials">Testimonials</a></li>
                  <li><a href="http://builtwith.phalconphp.com/">Built with Phalcon</a></li>
                  <li><a href="http://store.phalconphp.com/">Store</a></li>
              </ul>
          </div>
          <div class="col-xs-4 col-sm-2">
              <h4>About</h4>
              <ul>
                  <li><a class="link-black" href="http://blog.phalconphp.com/">Blog</a></li>
                  <li><a href="http://phalconphp.com/en/about">About</a></li>
                  <li><a href="http://phalconphp.com/en/team">Team</a></li>
                  <li><a href="http://phalconphp.com/en/roadmap">Roadmap</a></li>
                  <li><a href="http://phalconphp.com/en/donate">Donate</a></li>
                  <li><a href="http://phalconphp.com/en/consulting">Consulting</a></li>
                  <li><a href="http://phalconphp.com/en/hosting">Hosting</a></li>
              </ul>
          </div>
          <div id="license-spaccer" class="visible-xs"></div>
          <div id="license-wrapper" class="col-xs-12 col-sm-4">
              <p class="license">

                  Found a typo or an error? Want to improve this document? The documentation sources are available on <a href="http://github.com/phalcon/docs">Github</a><br>
                  Need support or have questions? Check our <a href="http://forum.phalconphp.com">Forum</a><br>
                  <br>

                  Phalcon Framework is released under the <a href="https://github.com/phalcon/cphalcon/blob/master/docs/LICENSE.md">new BSD license</a>.<br>
                  Except where otherwise noted, content on this site is licensed under the
                    <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License.</a>

                <div class="design">
                  <span>Designed by:</span>

                  <a href="http://www.fog-city.net/" class="fogcity" target="_blank" title="Fog City Software"><span>Fog City Software</span></a>
              </div>
          </div>
      </div>
  </div>
</footer>

    </div>
    <script type="text/javascript">
    $(window).on("load", function(){
      var cx = '009733439235723428699:lh9ltjgvdz8';
      var gcse = document.createElement('script');
      gcse.type = 'text/javascript';
      gcse.async = true;
      gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(gcse, s);
    });
    </script>

  </body>
</html>